package com.woniuxy.controller;


import com.woniuxy.demo.Result;
import com.woniuxy.dto.GoodsAppraisalHistoryDto;
import com.woniuxy.dto.GoodsEvaluateHistoryDto;
import com.woniuxy.dto.commonDto.BaseDto;
import com.woniuxy.enums.CodeEnum;
import com.woniuxy.exception.GoodsEvaluateException;
import com.woniuxy.param.GoodsAppraisalHistoryParam;
import com.woniuxy.param.GoodsEvaluateHistoryParam;
import com.woniuxy.param.GoodsEvaluateParam;
import com.woniuxy.service.GoodsEvaluateHistoryService;
import com.woniuxy.service.GoodsEvaluationService;
import com.woniuxy.util.WoniuBeanUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 历史估价记录 前端控制器
 * </p>
 *
 * @author zcx,ftl,gr,rhs
 * @since 2022-01-06
 */
@RestController
@RequestMapping("/goods-evaluate-history")
@Api(tags = "历史评估记录的接口")
public class GoodsEvaluateHistoryController {
    @Resource
    private GoodsEvaluateHistoryService goodsEvaluateHistoryService;

    @GetMapping("/getGoodsAppraisal")
    @ApiOperation("查询所有历史评估记录")
    public Result getGoodsAppraisal(){

        return Result.newInstance().setCode(200).setMsg("查询成功")
                .setData(goodsEvaluateHistoryService.list());
    }

    @ApiOperation("分页获取历史评估记录")
    @PostMapping("/getEvaluateHistory")
    public Result getEvaluateHistory(@RequestBody GoodsEvaluateHistoryParam gehp) {
        BaseDto<GoodsEvaluateHistoryDto> evaluateHistory = goodsEvaluateHistoryService.getEvaluateHistory(gehp);
        return Result.newInstance().setCode(200).setMsg("查询成功").setData(evaluateHistory);
    }

    @ApiOperation("添加评估记录信息")
    @PostMapping("/addEvaluateHistory")
    public Result addEvaluateHistory(@RequestBody GoodsEvaluateParam gep) {
        //参数验证

        if (goodsEvaluateHistoryService.addEvaluate(gep)) {
            GoodsEvaluateHistoryDto goodsEvaluateHistoryDto = WoniuBeanUtils.copyObject(gep, GoodsEvaluateHistoryDto.class);

            return new Result().setCode(200).setMsg("添加成功").setData(goodsEvaluateHistoryDto);
        }
        throw new GoodsEvaluateException(CodeEnum.Evaluate_SAVE_FAIL_1.getMessage()
                , CodeEnum.Evaluate_SAVE_FAIL_1.getCode());
    }

}

